package com.satan.elasticsearch.controller;

/**
 * @Author: Demon
 * @Date: 2024/2/17 11:24
 * @Description:
 **/

import com.satan.elasticsearch.dto.req.HotelAddReqDto;
import com.satan.elasticsearch.dto.req.HotelPageReqDto;
import com.satan.elasticsearch.dto.req.HotelSearchReqDto;
import com.satan.elasticsearch.dto.req.HotelUpdateReqDto;
import com.satan.elasticsearch.dto.resp.RestResp;
import com.satan.elasticsearch.service.HotelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/hotel")
@Tag(name = "酒店管理")
@RequiredArgsConstructor
public class HotelController {

    private final HotelService hotelService;



    @PostMapping("/list")
    @Operation(description = "关键字搜索酒店")
    public RestResp search(@RequestBody HotelSearchReqDto dto) throws IOException {
        return hotelService.search(dto);
    }
    //酒店竞价排名
    @GetMapping("/list2")
    @Operation(description = "关键字搜索酒店")
    public RestResp search2(@ParameterObject HotelSearchReqDto dto) throws IOException {
        return hotelService.search2(dto);
    }
    @Operation(description = "聚合查询")
    @PostMapping("/filters")
    public RestResp getFilters(@RequestBody HotelSearchReqDto dto) throws IOException {
        return hotelService.getFilters(dto);
    }
    @Operation(description = "建议词")
    @GetMapping("suggest")
    public RestResp getSuggestions(@RequestParam("key") String key) throws IOException {
        return hotelService.getSuggestions(key);
    }
    @Operation(description = "分页查询")
    @GetMapping("/list")
    public RestResp hotelList(@ParameterObject HotelPageReqDto dto){
        return hotelService.getPage(dto);
    }

    @PostMapping
    public RestResp saveHotel(@RequestBody HotelAddReqDto dto){
        // 新增酒店

        return hotelService.saveHotel(dto);
    }

    @PutMapping
    public RestResp updateHotel(@RequestBody HotelUpdateReqDto dto){
        return hotelService.updateHotel(dto);

    }

    @DeleteMapping("/{id}")
    public RestResp deleteHotel(@PathVariable("id") Long id) {
        return hotelService.deleteHotel(id);
    }
}
